import java.awt.Container;
import java.io.IOException;

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;


public class SimpleGUI extends JFrame{
	private static final long serialVersionUID = 9005379525508980913L;
	private ClojureWrapper wrapper;
	private ClojureListener clistener = new ClojureListener() {
		
		@Override
		public void receiveOutput(String output) {
			outputLabel.setText(outputLabel.getText()+output);
		}
		
		@Override
		public void receiveError(String error) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void consizeEnded() {
			JOptionPane.showMessageDialog(SimpleGUI.this, "Consize hat sich beendet.");
		}
	};
	private JLabel outputLabel;

	public SimpleGUI(){
		wrapper = new ClojureWrapper();
		wrapper.setListener(clistener);
		
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		setContentPane(createContentPane());
		this.pack();
		this.setVisible(true);
		
		try {
			wrapper.init();
			wrapper.startConsize();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	private Container createContentPane() {
		JPanel pane = new JPanel();
		pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
		outputLabel = new JLabel("IDE by Alex Haas v0.1\n");
		pane.add(outputLabel);
		return pane;
	}

	public static void main(String[] args){
		new SimpleGUI();
	}
}
